<?php
class Project extends DataObject{
    static $db = array(
		'Name'			=> 'Varchar(255)'
    );
    
    static $has_one = array(        
		'ProjectPage'	=> 'ProjectPage',
    );
	
	public static $has_many = array(
		'ProjectImages'		=> 'ProjectImage',
	);
    
    function getCMSFields_forPopup() {		
        $fields = new FieldSet(); 
        $fields->push(new TextField('Name', 'Name'));                        
		$image_field = new ImageDataObjectManager(
            $this,
            'ProjectImages',
            'ProjectImage',
			'Image',
			array('Image'  => 'Project image')
        );		
		$image_field->setAddTitle('image');
        $fields->push($image_field);
        
        return $fields;
    }

	public function delegateThumbnail() {
		$image = null;
		
		if($this->ProjectImages()){
			$project_image = $this->ProjectImages()->First();
			if($project_image){
				$image = $project_image->Image()->CroppedImage(50, 50);	
			}		 
		}
		
		return $image;
	} 
}